package com.atguigu.hellomp;

import com.atguigu.hellomp.entity.User;
import com.atguigu.hellomp.mapper.UserMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

/**
 * @author 张智勇
 * @date 2025年08月13日 20:04
 */


@SpringBootTest
public class test3 {

    @Autowired
    UserMapper userMapper;

    @Test
    public void test1(){
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.like("name","j");

        List<User> userList = userMapper.selectList(userQueryWrapper);
        System.out.println("userList = " + userList);
    }

    @Test
    public void test2(){
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.orderByDesc("age");

        List<User> userList = userMapper.selectList(userQueryWrapper);
        System.out.println("userList = " + userList);
    }

    @Test
    public void test3(){
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.ge("age",20);
        userQueryWrapper.le("age",30);

        List<User> userList = userMapper.selectList(userQueryWrapper);
        userList.forEach(System.out::println);
    }


    @Test
    public void test04(){
        User user = new User();
        user.setName("zhangzhiyong");
        user.setAge(23);
        user.setEmail("test@test.com");
        userMapper.insert(user);
    }
    @Test
    public void test05(){

        User user = userMapper.selectById(1);
        user.setName("xiaoming");
        userMapper.updateById(user);
    }
    @Test
    public void test06(){
        User user = userMapper.selectById(1);
        user.setName("xiaoming");
        userMapper.updateById(user);
    }






}
